<?php
	include_once $_SERVER['DOCUMENT_ROOT'] . '/projet_mosquee/AMC/conf/conf.site.inc.php';
	// include_once $_SERVER['DOCUMENT_ROOT'] . '/inscriptions/conf/conf.site.inc.php';
	
	include_once ELEVE_CLASS;
	include_once PARENT_CLASS;
	include_once FUNCTIONS_FILE;
	include_once INSCRIPTION_CLASS;
	
	connexion ();
	
	$eleve = new eleve ($db);
	
	switch ($_POST["action"]) {
            case "inscription_arabe":
                $result = $eleve->eleveInscriptionArabe($_POST["idInscription"], $_POST["etat"]);
                break;
		
            case "inscription_coran":
                $result = $eleve->eleveInscriptionCoran($_POST["idInscription"], $_POST["etat"]);
                break;

            case "eleve_creation":
                $db->MysqlQuery("START TRANSACTION;");
                $nom = $_POST["inscription_nom"];
                $prenom = $_POST["inscription_prenom"];
                $email = $_POST["inscription_email"];
                $login = $_POST["inscription_login"];
                $password = $_POST["inscription_password"];
                $sexe = $_POST["inscription_sexe"];
                $date_naissance = $eleve->phpToMysqlDate($_POST["inscription_date_naissance"]);
                $id_parent = $_POST["idParent"];

                $parent = new parent_class($db);
                $idUser = $parent->createNewUser($login, $password, $email, $nom, $prenom);
                if ($idUser) {
                    $idEleve = $eleve->newEleve($sexe, $date_naissance, $idUser, $id_parent);
                    if ($idEleve) {
                                            $inscription = new inscription($db);
                                            $idInscription = $inscription->newInscription($idEleve);
                                            if ($idInscription) {
                                                    $db->MysqlQuery("COMMIT;");
                                                    echo $id_parent;
                                            }
                                            else {
                                                    $db->MysqlQuery("ROLLBACK;");
                                                    echo 0;
                                                    return false;
                                            }
                    }
                    else {
                                            $db->MysqlQuery("ROLLBACK;");
                        echo 0;
                        return false;
                    }
                }
                else {
                                    $db->MysqlQuery("ROLLBACK;");
                    echo 0;
                    return false;
                }
                break;
        }
?>